package com.gzhryc.shared_device.pcl.code.dao.db;

import com.gzhryc.common.DateTools;
import com.gzhryc.common.NumberTools;
import com.gzhryc.jdbc.annotaion.Column;
import com.gzhryc.jdbc.annotaion.DateBranchTable;
import com.gzhryc.jdbc.annotaion.Id;
import com.gzhryc.jdbc.annotaion.Table;
import com.gzhryc.jdbc.enums.DateBranchTableType;
import com.gzhryc.shared_device.base.enums.EPayType;
import com.gzhryc.shared_device.base.models.IDeviceOrder;
import com.gzhryc.shared_device.pcl.code.dao.enums.EPCLCostMode;
import com.gzhryc.shared_device.pcl.code.dao.enums.PCLOrderEnum;

import java.io.Serializable;
import java.util.Date;

@DateBranchTable(type= DateBranchTableType.year)
@Table(name="pcl_order")
public class PCLOrder implements IDeviceOrder, Serializable {

    private static final long serialVersionUID = 1L;

	@Id(auto = false)
    @Column(name = "trade_no",length = 32,notNull = true)
    protected String tradeNo;

    @Column(name = "device_type_id", notNull = true,note = "设备类型ID")
    protected String deviceTypeId;

    @Column(name = "device_type_name", notNull = true,note = "设备类型名称")
    protected String deviceTypeName;

    @Column(name = "charging_cable_sn", notNull = true,note = "线充序列号")
    protected String chargingCableSn;

    @Column(name = "bind_note",note = "设备绑定信息")
    protected String bindNote;

    @Column(name = "cost_mode",notNull = true,defVal = "1",note = "收费模式，1:套餐收费")
    protected Integer costMode;

    @Column(name = "set_meal_id", notNull = true,note = "套餐序号")
    protected Integer setMealId;

    @Column(name = "set_meal_name", notNull = true,note = "套餐名称")
    protected String setMealName;

    @Column(name = "use_times", notNull = true,note = "使用时长，单位：分钟")
    protected Integer useTimes;

    @Column(name="pwd_index",note = "密码序列")
    protected String pwdIndex;

    @Column(name="pwd",note = "密码")
    protected String pwd;

    @Column(name = "start_date")
    protected Date startDate;

    @Column(name = "end_date")
    protected Date endDate;

    //设备使用属性End

    @Column(name = "member_id", notNull = true, note = "会员ID")
    protected Long memberId;

    @Column(name = "member_name", note = "会员名称")
    protected String memberName;

    @Column(name = "member_phone", length = 16,note = "会员手机号")
    protected String memberPhone;

    @Column(name = "agent_id", note = "代理ID")
    protected Long agentId;

    @Column(name = "place_id", notNull = true, note = "网点ID")
    protected Long placeId;

    @Column(name = "place_name", note = "网点名称")
    protected String placeName;

    @Column(note = "省")
    protected String province;

    @Column(note = "市")
    protected String city;

    @Column(name = "city_area",note = "城区")
    protected String cityArea;

    @Column(name = "area_code", length = 128, note = "地区ID，以逗号分隔")
    protected String areaCode;

    @Column(length = 64, note = "网点地址")
    protected String address;

    @Column(length = 10, decimalLen = 6, note = "经度")
    protected Double longitude;

    @Column(length = 10, decimalLen = 6, note = "纬度")
    protected Double latitude;

    //支付属性Start

    //订单金额大于等于支付金额，其误差来源于优惠
    @Column(name = "money", notNull = true,defVal = "0",note = "订单金额，单位：厘")
    protected Long money;

    @Column(name = "discount_money", notNull = true,defVal = "0",note = "优惠金额，单位：厘")
    protected Long discountMoney;

    @Column(name = "pay_money", notNull = true,defVal = "0",note = "支付金额，单位：分")
    protected Integer payMoney;

    @Column(name = "wallet_money", notNull = true,defVal = "0",note = "钱包金额，单位：厘")
    protected Long walletMoney;

    @Column(name = "coupon_id",note = "优惠券ID")
    protected String couponId;

    @Column(name = "coupon_title",length = 255,note = "优惠券标题")
    protected String couponTitle;

    @Column(name = "pay_type",notNull = true,defVal = "1",note = "支付类型")
    protected Integer payType;

    @Column(name = "pay_trade_no",length = 32,note = "支付订单")
    protected String payTradeNo;

    @Column(name = "pay_date", note = "支付时间")
    protected Date payDate;

    @Column(name = "pay_state",notNull = true, defVal = "1", note = "订单支付状态")
    protected Integer payState;

    //支付属性End

    @Column(notNull = true, defVal = "1", note = "订单状态")
    protected Integer state;

    @Column(name = "operate_state",notNull = true, defVal = "1", note = "操作状态，数据库锁字段")
    protected Integer operateState;

    @Column(name = "finish_date",note = "完成时间")
    protected Date finishDate;

    @Column(name = "cancel_date",note = "撤销时间")
    protected Date cancelDate;

    @Column(name = "update_date", autoUpdateTime = true, note = "修改时间")
    protected Date updateDate;

    @Column(name = "create_date")
    protected Date createDate;

    public String getTradeNo() {
        return tradeNo;
    }

    public void setTradeNo(String tradeNo) {
        this.tradeNo = tradeNo;
    }

    public String getDeviceTypeId() {
        return deviceTypeId;
    }

    public void setDeviceTypeId(String deviceTypeId) {
        this.deviceTypeId = deviceTypeId;
    }

    public String getDeviceTypeName() {
        return deviceTypeName;
    }

    public void setDeviceTypeName(String deviceTypeName) {
        this.deviceTypeName = deviceTypeName;
    }

    public String getChargingCableSn() {
        return chargingCableSn;
    }

    public void setChargingCableSn(String chargingCableSn) {
        this.chargingCableSn = chargingCableSn;
    }

    public String getBindNote() {
        return bindNote;
    }

    public void setBindNote(String bindNote) {
        this.bindNote = bindNote;
    }

    public Integer getCostMode() {
        return costMode;
    }

    public void setCostMode(Integer costMode) {
        this.costMode = costMode;
    }

    public Integer getSetMealId() {
        return setMealId;
    }

    public void setSetMealId(Integer setMealId) {
        this.setMealId = setMealId;
    }

    public String getSetMealName() {
        return setMealName;
    }

    public void setSetMealName(String setMealName) {
        this.setMealName = setMealName;
    }

    public Integer getUseTimes() {
        return useTimes;
    }

    public void setUseTimes(Integer useTimes) {
        this.useTimes = useTimes;
    }

    public String getPwdIndex() {
        return pwdIndex;
    }

    public void setPwdIndex(String pwdIndex) {
        this.pwdIndex = pwdIndex;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public Long getMemberId() {
        return memberId;
    }

    public void setMemberId(Long memberId) {
        this.memberId = memberId;
    }

    public String getMemberName() {
        return memberName;
    }

    public void setMemberName(String memberName) {
        this.memberName = memberName;
    }

    public String getMemberPhone() {
        return memberPhone;
    }

    public void setMemberPhone(String memberPhone) {
        this.memberPhone = memberPhone;
    }

    public Long getAgentId() {
        return agentId;
    }

    public void setAgentId(Long agentId) {
        this.agentId = agentId;
    }

    public Long getPlaceId() {
        return placeId;
    }

    public void setPlaceId(Long placeId) {
        this.placeId = placeId;
    }

    public String getPlaceName() {
        return placeName;
    }

    @Override
    public String getPlaceAreaName() {
        return this.province + "-" + this.city + "-" + this.cityArea;
    }

    public void setPlaceName(String placeName) {
        this.placeName = placeName;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCityArea() {
        return cityArea;
    }

    public void setCityArea(String cityArea) {
        this.cityArea = cityArea;
    }

    public String getAreaCode() {
        return areaCode;
    }

    public void setAreaCode(String areaCode) {
        this.areaCode = areaCode;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Double getLongitude() {
        return longitude;
    }

    public void setLongitude(Double longitude) {
        this.longitude = longitude;
    }

    public Double getLatitude() {
        return latitude;
    }

    public void setLatitude(Double latitude) {
        this.latitude = latitude;
    }

    public Long getMoney() {
        return money;
    }

    public void setMoney(Long money) {
        this.money = money;
    }

    public Long getDiscountMoney() {
        return discountMoney;
    }

    public void setDiscountMoney(Long discountMoney) {
        this.discountMoney = discountMoney;
    }

    public Integer getPayMoney() {
        return payMoney;
    }

    public void setPayMoney(Integer payMoney) {
        this.payMoney = payMoney;
    }

    public Long getWalletMoney() {
        return walletMoney;
    }

    @Override
    public Long getIncomeMoney() {
        if(this.walletMoney == null){
            this.walletMoney = 0L;
        }
        if(this.payMoney == null){
            this.payMoney = 0;
        }
        return this.walletMoney + NumberTools.changeMoneyLi(NumberTools.changeMoney(this.payMoney));
    }

    public void setWalletMoney(Long walletMoney) {
        this.walletMoney = walletMoney;
    }

    public String getCouponId() {
        return couponId;
    }

    public void setCouponId(String couponId) {
        this.couponId = couponId;
    }

    public String getCouponTitle() {
        return couponTitle;
    }

    public void setCouponTitle(String couponTitle) {
        this.couponTitle = couponTitle;
    }

    public Integer getPayType() {
        return payType;
    }

    public void setPayType(Integer payType) {
        this.payType = payType;
    }

    public String getPayTradeNo() {
        return payTradeNo;
    }

    public void setPayTradeNo(String payTradeNo) {
        this.payTradeNo = payTradeNo;
    }

    public Date getPayDate() {
        return payDate;
    }

    public void setPayDate(Date payDate) {
        this.payDate = payDate;
    }

    public Integer getPayState() {
        return payState;
    }

    public void setPayState(Integer payState) {
        this.payState = payState;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Integer getOperateState() {
        return operateState;
    }

    public void setOperateState(Integer operateState) {
        this.operateState = operateState;
    }

    public Date getFinishDate() {
        return finishDate;
    }

    public void setFinishDate(Date finishDate) {
        this.finishDate = finishDate;
    }

    public Date getCancelDate() {
        return cancelDate;
    }

    public void setCancelDate(Date cancelDate) {
        this.cancelDate = cancelDate;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public String getPayStateName(){
        return PCLOrderEnum.PayState.note(this.payState);
    }

    public String getCostModeName(){
        return EPCLCostMode.note(this.costMode);
    }
    public String getMoneyStr(){
        return NumberTools.getMoneyLiStr(this.money);
    }

    public String getDiscountMoneyStr(){
        return NumberTools.getMoneyLiStr(this.discountMoney);
    }

    public String getPayMoneyStr(){
        return NumberTools.getMoneyStr(this.payMoney);
    }

    public String getWalletMoneyStr(){
        return NumberTools.getMoneyLiStr(this.walletMoney);
    }

    public String getStateName(){
        return PCLOrderEnum.State.note(this.state);
    }

    public String getPayTypeName(){
        return EPayType.note(this.payType);
    }

    public String getUseTimesStr(){
        if(this.useTimes == null || this.useTimes == 0){
            if(this.startDate != null){
                this.useTimes = (int)DateTools.differenceMinute(this.startDate,new Date());
            }
        }
        if(this.useTimes != null) {
            if (this.useTimes > 60) {
                long hour = this.useTimes / 60;
                long minute = this.useTimes % 60;
                if (minute > 0) {
                    return hour + "小时" + minute + "分钟";
                } else {
                    return hour + "小时";
                }
            } else {
                return this.useTimes + "分钟";
            }
        }
        return "1分钟内";
    }
}
